package com.crm.system.service.impl.contractManager;

import com.crm.common.model.DhPageInfo;
import com.crm.model.vo.csd.customerManager.CustomerServiceWorkLogVO;
import com.crm.service.csd.customerManager.ContractContactDbService;
import com.crm.system.service.csd.customerManager.ContractContactService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author luojie
 * @date 2021/9/3 9:20
 */
@Service
public class ContractContactServiceImpl implements ContractContactService {

    @Autowired
    private ContractContactDbService contractContactDbService;

    /***
     * @Description:根据合同id获取合同审核列表
     * @Param: contractId 合同id
     * @Author: luojie
     * @Date: 2021/9/3 10:02
     */
    @Override
    public DhPageInfo<CustomerServiceWorkLogVO> selectContractContactWorkLogByContractId(Integer pageIndex,Integer pageSize,String sortName,String sortOrder,String contractId) {
        if (pageIndex != null && pageSize != null) {
            PageHelper.startPage(pageIndex, pageSize);
        }

        //排序
        StringBuilder order = new StringBuilder();
        if (!StringUtils.isBlank(sortName) && !StringUtils.isBlank(sortOrder)) {
            switch (sortName) {
                case "createTm": {
                    order.append("t.create_tm ").append(sortOrder);//创建时间
                }
                break;
                default:
                    break;
            }

        }
        List<CustomerServiceWorkLogVO> customerWorkLogList =contractContactDbService.selectContractContactWorkLogByContractId(contractId,order.toString());
        PageInfo<CustomerServiceWorkLogVO> pageInfo = new PageInfo<CustomerServiceWorkLogVO>(customerWorkLogList);
        return new DhPageInfo<CustomerServiceWorkLogVO>(pageInfo, customerWorkLogList);
    }
}
